<%@page import="util.MD5Util"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
//1.设置字符集
	request.setCharacterEncoding("utf-8");

	// 2.获取参数
	
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	if(username==null || password==null){
		response.sendRedirect("register.jsp");
	}

	// 3.链接数据库（JDBC）
	
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://127.0.0.1:3306/tb108";
		String user = "root";
		String pwd = "root";
		Connection con =   DriverManager.getConnection(url, user, pwd);
		PreparedStatement ps =  con.prepareStatement("insert into sys_user (uname,upassword) values (?,?)");
		ps.setString(1, username);
		ps.setString(2, MD5Util.MD5(MD5Util.MD5(password)+"TB108"));
	
		int i = ps.executeUpdate();
		
		if(i>0){
			response.sendRedirect("login.jsp");			
		}else{
			request.setAttribute("msg","注册失败");
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}
		ps.close();
		con.close();
		
		
		
		
		
		
		
	
%>